import { request } from '../../request/index'

//Page Object
Page({
  data: {
    // 轮播图
    swiperList: [],
    // 导航栏
    catesList: [],
    // 楼层
    floorList: []
  },
  //options(Object)
  onLoad: function () {
    this.getBannerList()
    this.getCatesList()
    this.getFloorList()
  },

  // 获取轮播图
  getBannerList () {
    request({
      url: '/home/swiperdata'
    }).then((result) => {
      // console.log(result);
      this.setData({
        swiperList: result
      })
    })
  },

  // 获取导航栏
  getCatesList () {
    request({
      url: '/home/catitems'
    }).then((result) => {
      // console.log(result);
      this.setData({
        catesList: result
      })
    })
  },

  floor: [],

  // 获取楼层
  getFloorList () {
    request({
      url: '/home/floordata'
    }).then((result) => {
      // console.log(result);
     
      const reg = new RegExp('/pages/goods_list', 'g')

      result.forEach(v => {
        return v.product_list.map(v1 => {
          // const str = v1.navigator_url
          return v1.navigator_url = v1.navigator_url.replace(reg, '/pages/goods_list/index')
        })
      });

      this.setData({
        floorList: result
      })

    })
  }
});
